package com.ruoyi.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.ruoyi.demo.domain.vo.meetDetailVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MeetDetailMapper extends BaseMapper<meetDetailVO> {
    @Select("SELECT theme, meet_content AS content, room.room_address AS roomAddress, start_time AS startTime, " +
            "  end_time AS endTime," +
            " num_respondents AS numRespondents, " +
            " actual_num AS actualNum, " +
            " meet.`status` AS `status`, " +
            " meet.created_at AS createdAt FROM meet,room where meet.room_id=room.room_id " +
            "and room.room_id=#{roomId} and meet.`status`=1")
    meetDetailVO getMeetDetailById(int roomId);
    @Select("select sys_user.user_name from meet,meet_user,sys_user " +
            "where meet.room_id=#{roomId} and meet.meet_id=meet_user.meet_id and meet_user.user_id = " +
            "sys_user.user_id and meet_user.is_attented=1 and meet.`status`=1")
    List<String> getMeetUserDetailById(int roomId);
    @Select("SELECT count(*) =(SELECT count(*) from meet_requests where room_id = #{roomId}) " +
            "FROM meet_requests " +
            "WHERE room_id=#{roomId} and (#{reserveEndTime} <= DATE_SUB(start_time, INTERVAL 30 MINUTE) or " +
            "DATE_ADD(end_time, INTERVAL 30 MINUTE) <= #{reserveStartTime})")
    int getIsMeetRequestsReserve(@Param("roomId") int roomId,
                         @Param("reserveEndTime") String reserveEndTime,
                         @Param("reserveStartTime") String reserveStartTime);
    @Select("SELECT count(*) =(SELECT count(*) from meet where room_id = #{roomId}) " +
            "FROM meet " +
            "WHERE room_id=#{roomId} and (#{reserveEndTime} <= DATE_SUB(start_time, INTERVAL 30 MINUTE) or " +
            "DATE_ADD(end_time, INTERVAL 30 MINUTE) <= #{reserveStartTime})")
    int getIsMeetReserve(@Param("roomId") int roomId,
                         @Param("reserveEndTime") String reserveEndTime,
                         @Param("reserveStartTime") String reserveStartTime);
}
